<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
  <title>信息管理系统</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <link th:href="@{/backend/jsoneditor/jsoneditor.css}" rel="stylesheet" type="text/css">
  <script th:src="@{/backend/jsoneditor/jsoneditor.js}"></script>
  <script type="text/javascript" th:src="@{/backend/scripts/jquery/jquery-1.7.1.js}"></script>
  <link th:href="@{/backend/style/authority/basic_layout.css}" rel="stylesheet" type="text/css">
  <link th:href="@{/backend/style/authority/common_style.css}" rel="stylesheet" type="text/css">
  <script type="text/javascript" th:src="@{/backend/scripts/authority/commonAll.js}"></script>
  <script type="text/javascript" th:src="@{/backend/scripts/jquery/jquery-1.4.4.min.js}"></script>
  <script th:src="@{/backend/scripts/My97DatePicker/WdatePicker.js}" type="text/javascript"
          defer="defer"></script>
  <script type="text/javascript"
          th:src="@{/backend/scripts/artDialog/artDialog.js?skin=default}"></script>
  <style type="text/css">
    #jsoneditor {
      width: 500px;
      height: 500px;
    }
  </style>
  <script type="text/javascript">
    $(document).ready(function () {

      /*
       * 取消
       */
      $("#cancelbutton").click(function () {
        window.history.back();
      });

      // create the editor
      const container = document.getElementById('jsoneditor')
      const options = {
        mode: 'code',
        modes: ['code', 'form', 'text', 'tree', 'view', 'preview'], // allowed modes
        onError: function (err) {
          alert(err.toString())
        },
        onModeChange: function (newMode, oldMode) {
          console.log('Mode switched from', oldMode, 'to', newMode)
        }
      }
      const editor = new JSONEditor(container, options)
      var content = $('#content').val();
      if (content) {
        console.log(content)
        editor.set(JSON.parse(content));
      }

      /*
       * 保存
       */
      $("#savebutton").click(function () {
        var id = $('#id').val();
        var status = $('#status').val();
        var order = $('#order').val();
        var name = $('#name').val();
        var title = $('#title').val();
        var image = $('#image').val();
        var desc = $('#desc').val();
        const content = editor.get()
        $.ajax({
          type: "POST",
          url: "lesson_update",
          data: JSON.stringify({
            "id": id,
            "status": status,
            "order": order,
            "name": name,
            "title": title,
            "desc": desc,
            "image": image,
            "content": content,
          }),
          contentType: "application/json",
          dataType: "json",
          success: function (data) {
            if (data) {
              var code = data.code
              if (code == 0) {
                alert("保存成功")
              }
            }
          }
        });
      });

      $("#previewbutton").click(function () {
        var id = $('#id').val();
        var status = $('#status').val();
        var order = $('#order').val();
        var name = $('#name').val();
        var title = $('#title').val();
        var image = $('#image').val();
        var desc = $('#desc').val();
        const content = editor.get()
        $.ajax({
          type: "POST",
          url: "lesson_preview",
          data: JSON.stringify({
            "id": id,
            "status": status,
            "order": order,
            "name": name,
            "title": title,
            "desc": desc,
            "image": image,
            "content": content,
          }),
          contentType: "application/json",
          dataType: "json",
          success: function (data) {
            if (data) {
              var hash = data.hash;
              window.open("/free_study/backend/lesson_preview_show?hash=" + hash);
            }
          }
        });
      });
    });
  </script>
</head>
<body>
<div class="" style="display: none; position: absolute;">
  <div class="aui_outer">
    <table class="aui_border">
      <tbody>
      <tr>
        <td class="aui_nw"></td>
        <td class="aui_n"></td>
        <td class="aui_ne"></td>
      </tr>
      <tr>
        <td class="aui_w"></td>
        <td class="aui_c">
          <div class="aui_inner">
            <table class="aui_dialog">
              <tbody>
              <tr>
                <td colspan="2" class="aui_header">
                  <div class="aui_titleBar">
                    <div class="aui_title" style="cursor: move; display: block;"></div>
                    <a class="aui_close" href="javascript:/*artDialog*/;"
                       style="display: block;">×</a></div>
                </td>
              </tr>
              <tr>
                <td class="aui_icon" style="display: none;">
                  <div class="aui_iconBg" style="background: none;"></div>
                </td>
                <td class="aui_main" style="width: auto; height: auto;">
                  <div class="aui_content" style="padding: 20px 25px;"></div>
                </td>
              </tr>
              <tr>
                <td colspan="2" class="aui_footer">
                  <div class="aui_buttons" style="display: none;"></div>
                </td>
              </tr>
              </tbody>
            </table>
          </div>
        </td>
        <td class="aui_e"></td>
      </tr>
      <tr>
        <td class="aui_sw"></td>
        <td class="aui_s"></td>
        <td class="aui_se" style="cursor: se-resize;"></td>
      </tr>
      </tbody>
    </table>
  </div>
</div>
<div style="position: absolute; z-index: 19700; top: -1970px; left: -1970px;">
  <iframe
      src="file:///Users/hinson/Downloads/%E5%90%8E%E5%8F%B0%E7%AE%A1%E7%90%86%E7%BD%91%E7%AB%99%E6%A8%A1%E6%9D%BFHTML%E6%A8%A1%E6%9D%BF_%E7%88%B1%E7%BB%99%E7%BD%91_aigei_com/%E5%90%8E%E5%8F%B0%E7%AE%A1%E7%90%86%E7%BD%91%E7%AB%99%E6%A8%A1%E6%9D%BFHTML%E6%A8%A1%E6%9D%BF-mb742/scripts/My97DatePicker/My97DatePicker.htm"
      frameborder="0" border="0" scrolling="no"></iframe>
</div>
<form id="submitForm" name="submitForm" action="/xngzf/archives/initFangyuan.action" method="post">
  <input type="hidden" name="fyID" value="14458625716623" id="fyID">
  <div id="container">
    <div class="ui_content">
      <table cellspacing="0" cellpadding="0" width="100%" align="left" border="0">
        <tbody>
        <tr>
          <td class="ui_text_rt">id</td>
          <td class="ui_text_lt">
            <input id="id" type="text" name="fangyuanEntity.fyCh" value="1"
                   class="ui_input_txt03" th:value="${lessonVo.id}">
          </td>
        </tr>
        <tr>
          <td class="ui_text_rt">状态</td>
          <td class="ui_text_lt">
            <select name="fangyuanEntity.zulinXingzhi" id="status" class="ui_select01">
              <option value="0" th:selected="${lessonVo.status==0}">未发布</option>
              <option value="1" th:selected="${lessonVo.status==1}">已发布</option>
            </select>
          </td>
        </tr>
				<tr>
					<td class="ui_text_rt">顺序</td>
					<td class="ui_text_lt">
						<input id="order" type="text" name="fangyuanEntity.fyCh" value="1"
									 class="ui_input_txt03" th:value="${lessonVo.order}">
					</td>
				</tr>
				<tr>
					<td class="ui_text_rt">名称</td>
					<td class="ui_text_lt">
						<input id="name" type="text" name="fangyuanEntity.fyCh" value="1"
									 class="ui_input_txt03" th:value="${lessonVo.name}">
					</td>
				</tr>
				<tr>
					<td class="ui_text_rt">标题</td>
					<td class="ui_text_lt">
						<input id="title" type="text" name="fangyuanEntity.fyCh" value="1"
									 class="ui_input_txt03" th:value="${lessonVo.title}">
					</td>
				</tr>
        <tr>
          <td class="ui_text_rt">封面图</td>
          <td class="ui_text_lt" style="margin-left: 10%">
            <input id="image" type="text" name="fangyuanEntity.fyCh" value="1"
                   class="ui_input_txt03" th:value="${lessonVo.image}">
          </td>
        </tr>
				<tr>
					<td class="ui_text_rt">描述</td>
					<td class="ui_text_lt" style="margin-left: 10%">
						<textarea id="desc" name="fangyuanEntity.fyCh"
									 class="ui_input_txt03" style="height: 100px" th:text="${lessonVo.desc}">
            </textarea>
					</td>
				</tr>
				<tr>
					<td class="ui_text_rt">内容</td>
					<td class="ui_text_lt" style="margin-left: 10%">
						<textarea name="fangyuanEntity.fyCh"
									 class="ui_input_txt03" hidden id="content" th:text="${lessonVo.rawContent}">
						</textarea>
            <div id="jsoneditor" style="width: 60%;"></div>
					</td>
				</tr>
        <tr>
          <td>&nbsp;</td>
          <td class="ui_text_lt">
						&nbsp;<input id="previewbutton" type="button" value="预览" class="ui_input_btn01">
            &nbsp;<input id="savebutton" type="button" value="保存" class="ui_input_btn01">
            &nbsp;<input id="cancelbutton" type="button" value="返回" class="ui_input_btn01">
          </td>
        </tr>
        </tbody>
      </table>
    </div>
  </div>
</form>
<div style="display:none">
  <script src="http://v7.cnzz.com/stat.php?id=155540&amp;web_id=155540" language="JavaScript"
          charset="gb2312"></script>
  <script src="http://c.cnzz.com/core.php?web_id=155540&amp;t=z" charset="utf-8"
          type="text/javascript"></script>
  <a href="https://www.cnzz.com/stat/website.php?web_id=155540" target="_blank"
     title="站长统计">站长统计</a></div>

</body>
</html>
